<template>
  <Chart :cdata="cdata" />
</template>

<script>
	import Chart from './chartBar.vue'
	export default {
		components: {
			Chart,
		},
		props: {
			dateStr: {
				type: String,
				default: ""
			},
			periodType: {
				type: String,
				default: "week"
			}
		},
		data() {
			return {
				url: {
					costTotalGroup: '/api/report/analysis/costTotalGroup',
				},
				cdata: {
					category: [],
					barData: []
				}
			};
		},
		watch: {
			periodType: {
				handler() {
					this.setData()
				}
			}
		},
		mounted() {
			this.setData();
		},
		methods: {
			// 根据自己的业务情况修改
			setData() {
				console.log(this.dateStr, "dateStr")
				var _this = this
				this.$ajax({
					method: 'get',
					url: this.url.costTotalGroup,
					params: {
						periodType: this.periodType,
						countType: "WN",
						dateStr: this.dateStr
					}
				}).then(function(resultData) {
					var resData = resultData.data.data
					var resList = resData.list
					_this.cdata.category = []
					_this.cdata.barData = []
					for (let i = 0; i < resList.length; i++) {
						if (_this.periodType == "year") {
							_this.cdata.category.push(resList[i].belong_period)
						} else {
							_this.cdata.category.push(resList[i].belong_period.substr(5, 10))
						}
						_this.cdata.barData.push(resList[i].total_product)
					}
					console.log(resData)
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
</style>
